package net.tngou.crawler.runnable;

import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.GenericObjectPool;

public class TestThreadPool {
	
	public static void main(String[] args) {
	PooledObjectFactory<BaseThread> factory =new MyPoolableObjectFactory();

	GenericObjectPool<BaseThread> pool= new GenericObjectPool<BaseThread>(factory);
	pool.setMaxIdle(20); // 能从池中借出的对象的最大数目
    pool.setMaxIdle(20); // 池中可以空闲对象的最大数目
    pool.setTimeBetweenEvictionRunsMillis(600000);// 间隔每过多少毫秒进行一次后台对象清理的行动
    pool.setNumTestsPerEvictionRun(-1);// －1表示清理时检查所有线程
    pool.setMinEvictableIdleTimeMillis(3000);// 设定在进行后台对象清理时，休眠时间超过了3000毫秒的对象为过期

	  for (int i = 0; i < 20; i++) {
         try {
             BaseThread simpleThread = (BaseThread) pool.borrowObject();
             simpleThread.setPool(pool);
         } catch (Exception ex) {
             System.out.println(ex);
         }
     }
	 
   }
}
